//
//  CMSServicesHandler+CMSTheme.m
//  CMSCharts
//
//  Created by symbio on 2023/2/14.
//

#import "CMSServicesHandler+CMSTheme.h"

@implementation CMSServicesHandler (CMSTheme)
/// 根据类型名获取当前的导航条状态
- (CMSThemeModel *)getThemeModelWithName:(NSString *)name {
    if (!(name.length > 0)) {
        name = @"light";
    }
    NSString *path = [NSString stringWithFormat:@"/appres/theme/%@",name];
    NSDictionary *dict = [self getDictFromJsonName:path];
    NSDictionary *colorDic = dict[@"colors"];
    NSDictionary *imageDic = dict[@"images"];
    CMSThemeModel *model = [CMSThemeModel new];
    model.colorDic = colorDic;
    model.imageDic = imageDic;
    model.name = name;
    return model;
}

- (NSDictionary *)getDictFromJsonName:(NSString *)jsonName {
   
    NSString *pathUI = [[NSBundle mainBundle] pathForResource:jsonName ofType:@"json"];
    NSData *dataUI = [[NSData alloc] initWithContentsOfFile:pathUI];
    NSString *hintStr = [NSString stringWithFormat:@"设置的主题%@找不到，请检查",jsonName];
    NSAssert(dataUI != nil, hintStr);
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:dataUI options:NSJSONReadingMutableContainers error:nil];
    return dic;
}

@end
